package cn.jucheng.www.yizhudan;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import cn.jucheng.jclibs.tools.MyLog;
import cn.jucheng.jclibs.tools.MyToast;
import cn.jucheng.jclibs.tools.SubStringUtils;
import cn.jucheng.www.yizhudan.global.AppManager;
import cn.jucheng.www.yizhudan.utils.DateUtils;
import cn.jucheng.www.yizhudan.widget.HexadecimalConver;
import cn.jucheng.www.yizhudan.widget.MyMessage;

@SuppressLint("UseValueOf")
public class LoginActivity extends MyBaseActivity {
    private EditText etXianShi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        etXianShi = (EditText) findViewById(R.id.etXianShi);
    }

    public void onDengLu(View v) {
        AppManager.getAppManager().xingMing = ((EditText) findViewById(R.id.etXingMing))
                .getText().toString();
        AppManager.getAppManager().xueHao = ((EditText) findViewById(R.id.etXueHao))
                .getText().toString();
        // Intent intent = new Intent(this, MainList1Activity.class);
        // startActivity(intent);
        // this.finish();
    }

    public void onTest(View v) {
        switch (v.getId()) {
            case R.id.yaow_buton:
                testReciveMsg(MyMessage.getMsgTestGenggaiyizhuzhuangtai(18, 1,1, 1));
                etXianShi.setText(MyMessage.getMsgTestGenggaiyizhuzhuangtai(15, 1,1, 1));
                break;
            case R.id.set_bton:
                Intent intents = new Intent(this, SettingsActivity.class);
                startActivity(intents);
                break;
            case R.id.page_buton:
                Intent intent_page = new Intent(this, PageActivity.class);
                startActivity(intent_page);
                break;
            case R.id.btnFSSaoMiaoErWeiMa://扫描病人二维码
                etXianShi.setText(MyMessage.getMsgSaomiaobingrenwandai());
                MyMessage.sendMessage(MyMessage.getMsgSaomiaobingrenwandai());
                break;
            case R.id.btnywSaoMiaoErWeiMa://扫描药物二维码
                etXianShi.setText(MyMessage.getMsgSaomiaobingrenyaowu(12));
                MyMessage.sendMessage(MyMessage.getMsgSaomiaobingrenyaowu(12));
                break;
            case R.id.btnFSQianZhi://学生点击签字
                String etYiZhuZhongLei = ((EditText) findViewById(R.id.etYiZhuZhongLei))
                        .getText().toString();
                if (TextUtils.isEmpty(etYiZhuZhongLei)) {
                    etYiZhuZhongLei = "1";
                }
                String etHangHao = ((EditText) findViewById(R.id.etHangHao))
                        .getText().toString();
                if (TextUtils.isEmpty(etHangHao)) {
                    etHangHao = "1";
                }
                try {
                    MyMessage.sendMessage(MyMessage.getMsgXueshengdianjiqianzi(
                            new Integer(etYiZhuZhongLei), new Integer(etHangHao)));
                    etXianShi.setText(MyMessage.getMsgXueshengdianjiqianzi(
                            new Integer(etYiZhuZhongLei), new Integer(etHangHao)));
                } catch (Exception e) {
                    MyToast.showToast(this, "请输入数字");
                }
                break;
            case R.id.btnJSBiaoDan://表单内容
                testReciveMsg(MyMessage.getMsgTestBiaodan(20, 1, 1, 1,
                        "{\"shuxueguanchajiludan\":[\"\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"xhdf\",\"\"]}"));
//			etXianShi.setText(MyMessage.getMsgTestBiaodan(15, 1, 1, 1, "内容"));
                break;
            case R.id.btnJSBingRenWanDaiXinXi://腕带信息
                testReciveMsg(MyMessage.getMsgTestBingrenwandaixinxi("姓名", "性别",
                        "35", "985626334", "6005", "骨科", "无过敏史", "诊断完毕"));
//			etXianShi.setText(MyMessage.getMsgTestBingrenwandaixinxi("姓名",
//					"性别", "13", "12345", "23", "科室", "无过敏史", "诊断"));
                break;
            case R.id.btnJSJiaoZhengSheBeiShiJian://校正设备时间
                testReciveMsg(MyMessage.getMsgTestJiaozhengshebeishijian(2017, 10,
                        10, 5, 20, 20));
//			etXianShi.setText(MyMessage.getMsgTestJiaozhengshebeishijian(2017,
//					10, 10, 5, 20, 20));
                break;
            case R.id.btnJSSheBeiZhuangTaiA0://
                testReciveMsg(MyMessage.getMsgXueshengzhuangtaidianliang(1, 10, 1));
//                etXianShi.setText(MyMessage.getMsgXueshengzhuangtaidianliang(1, 10, 1));
                break;
            case R.id.btnJSSheBeiZhuangTaiAD:
                testReciveMsg(MyMessage.getMsgTestShebeizhuangtaiAd(1, 1));
//                etXianShi.setText(MyMessage.getMsgTestShebeizhuangtaiAd(1, 1));
                break;
            case R.id.addSetting:
                Intent intent = new Intent(Settings.ACTION_DATE_SETTINGS);
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    @Override
    protected void HandlerMessage(Message msg) {
        // TODO Auto-generated method stub
        switch (msg.what) {
            case MyMessage.MLZ_BINGRENWANDAIXINXI://病人腕带信息
                Object z = msg.obj;
                String a = (String) z;
                String str = a.substring(52);
                etXianShi.setText(HexadecimalConver.toStringHex(str));
                break;
            case MyMessage.MLZ_JIAOZHENGSHEBEISHIJIAN://校正时间
                Object z1 = msg.obj;
                String a1 = (String) z1;
                String atr = a1.substring(52);
                int nian = Integer
                        .parseInt(SubStringUtils.substring(a1,
                                52, 56), 16);
                int yue = Integer
                        .parseInt(SubStringUtils.substring(a1,
                                56, 58), 16);
                int ri = Integer
                        .parseInt(SubStringUtils.substring(a1,
                                58, 60), 16);
                int shi = Integer
                        .parseInt(SubStringUtils.substring(a1,
                                60, 62), 16);
                int fen = Integer
                        .parseInt(SubStringUtils.substring(a1,
                                62, 64), 16);
                int miao = Integer
                        .parseInt(SubStringUtils.substring(a1,
                                64, 66), 16);
                etXianShi.setText(nian + " " + yue + " " + ri + " " + shi + " " + fen + " " + miao);
                String time = nian + "-" + yue + "-" + ri + " " + shi + ":" + fen + ":" + miao;
                String date = DateUtils.timeLogic(time);
                MyToast.showTestToast(LoginActivity.this, date);

                break;
            case MyMessage.MLZ_BIAODAN://学生填写的表单
                Object z2 = msg.obj;
                String a2 = (String) z2;
                int biaoDanType = Integer
                        .parseInt(SubStringUtils.substring(a2,
                                52, 54), 16);
                int yiZhuType = Integer
                        .parseInt(SubStringUtils.substring(a2,
                                54, 56), 16);
                int yiZhuHangHao = Integer
                        .parseInt(SubStringUtils.substring(a2,
                                56, 60), 16);
                int yiZhuZhuangTai = Integer
                        .parseInt(SubStringUtils.substring(a2,
                                60, 62), 16);
                String yiZhu = a2.substring(62);
                etXianShi.setText(biaoDanType + " " + yiZhuType + " " + yiZhuHangHao + " " + yiZhuZhuangTai + " " + HexadecimalConver.toStringHex(yiZhu));
                break;
            case MyMessage.MLZ_GENGGAIYIZHUZHUANGTAI://更改医嘱状态
                Object z3 = msg.obj;
                String a3 = (String) z3;
                int yiZhuTypes = Integer
                        .parseInt(SubStringUtils.substring(a3,
                                52, 54), 16);
                int hangHao = Integer
                        .parseInt(SubStringUtils.substring(a3,
                                54, 58), 16);
                int zhuangTai = Integer
                        .parseInt(SubStringUtils.substring(a3,
                                58, 60), 16);
                MyLog.d("mwh", "yiZhuTypes" + yiZhuTypes);
                etXianShi.setText(yiZhuTypes + " " + hangHao + " " + zhuangTai);
                break;
            case MyMessage.MLZ_SHEBEIZHUANGTAI_A0://设备状态以及电量
                Object z4 = msg.obj;
                String a4 = (String) z4;
                int bianHao = Integer
                        .parseInt(SubStringUtils.substring(a4,
                                52, 54), 16);
                int zhuangTais = Integer
                        .parseInt(SubStringUtils.substring(a4,
                                54, 56), 16);
                MyLog.d("mwh", "zhuangTais" + zhuangTais);
                etXianShi.setText(bianHao + " " + zhuangTais);
                break;
            case MyMessage.MLZ_SHEBEIZHUANGTAI_AD://设备状态以及电量
                Object z5 = msg.obj;
                String a5 = (String) z5;
                int bianHaos = Integer
                        .parseInt(SubStringUtils.substring(a5,
                                52, 54), 16);
                int zhuangTaiss = Integer
                        .parseInt(SubStringUtils.substring(a5,
                                54, 56), 16);
                int zhuang = Integer
                        .parseInt(SubStringUtils.substring(a5,
                                56, 58), 16);
                MyLog.d("mwh", "zhuangTaiss" + zhuangTaiss);
                etXianShi.setText(bianHaos + " " + zhuangTaiss + " " + zhuang);
                break;
            default:
                break;
        }
    }

    @Override
    public void exc() {
        // TODO Auto-generated method stub

    }


}
